home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import generators
- import warnings
- from nevow import stan
- from nevow.inevow import IData, IRequest
- from nevow.stan import Unset
- from nevow.util import qual
- from zope.interface import providedBy
-
- def megaGetInterfaces(adapter):
- return [ qual(x) for x in providedBy(adapter) ]
-
- dataqual = qual(IData)
-
- class WebContext(object):
- _remembrances = None
- tag = None
- _slotData = None
- parent = None
- locateHook = None
- isAttrib = property((lambda self: False))
- inURL = property((lambda self: False))
- inJS = property((lambda self: False))
- inJSSingleQuoteString = property((lambda self: False))
- precompile = property((lambda self: False))
-
- def arg(self, get, default = None):
- """Placeholder until I can find Jerub's implementation of this
-
- Return a single named argument from the request arguments
- """
- req = self.locate(IRequest)
- return req.args.get(get, [
- default])[0]
-
-
- def __init__(self, parent = None, tag = None, remembrances = None):
- self.tag = tag
- sd = getattr(tag, 'slotData', None)
- if sd is not None:
- self._slotData = sd
-
- self.parent = parent
- self._remembrances = remembrances
-
-
- def remember(self, adapter, interface = None):
- """Remember an object that implements some interfaces.
- Later, calls to .locate which are passed an interface implemented
- by this object will return this object.
-
- If the 'interface' argument is supplied, this object will only
- be remembered for this interface, and not any of
- the other interfaces it implements.
- """
- if interface is None:
- interfaceList = megaGetInterfaces(adapter)
- if not interfaceList:
- interfaceList = [
- dataqual]
-
- else:
- interfaceList = [
- qual(interface)]
- if self._remembrances is None:
- self._remembrances = { }
-
- for interface in interfaceList:
- self._remembrances[interface] = adapter
-
- return self
-
-
- def locate(self, interface, depth = 1, _default = object()):
- '''Locate an object which implements a given interface.
- Objects will be searched through the context stack top
- down.
- '''
- key = qual(interface)
- currentContext = self
- while True:
- if depth < 0:
- full = []
- while True:
-
- try:
- full.append(self.locate(interface, len(full) + 1))
- continue
- except KeyError:
- break
- continue
-
-
- None<EXCEPTION MATCH>KeyError
- if full:
- return full[depth]
- return None
- _remembrances = currentContext._remembrances
- if _remembrances is not None:
- rememberedValue = _remembrances.get(key, _default)
- if rememberedValue is not _default:
- depth -= 1
- if not depth:
- return rememberedValue
-
-
- locateHook = currentContext.locateHook
- if locateHook is not None:
- result = locateHook(interface)
- if result is not None:
- currentContext.remember(result, interface)
- return result
-
- contextParent = currentContext.parent
- if contextParent is None:
- raise KeyError, 'Interface %s was not remembered.' % key
- contextParent is None
- currentContext = contextParent
-
-
- def chain(self, context):
- """For nevow machinery use only.
-
- Go to the top of this context's context chain, and make
- the given context the parent, thus continuing the chain
- into the given context's chain.
- """
- top = self
- while top.parent is not None:
- if top.parent.tag is None:
- break
-
- top = top.parent
- if top is context:
- return None
- continue
- top is context
- top.parent = context
-
-
- def fillSlots(self, name, stan):
- """Set 'stan' as the stan tree to replace all slots with name 'name'.
- """
- if self._slotData is None:
- self._slotData = { }
-
- self._slotData[name] = stan
-
-
- def locateSlotData(self, name):
- '''For use by nevow machinery only, or for some fancy cases.
-
- Find previously remembered slot filler data.
- For use by flatstan.SlotRenderer'''
- currentContext = self
- while True:
- if currentContext._slotData:
- data = currentContext._slotData.get(name, Unset)
- if data is not Unset:
- return data
-
- if currentContext.parent is None:
- raise KeyError, "Slot named '%s' was not filled." % name
- currentContext.parent is None
- currentContext = currentContext.parent
-
-
- def clone(self, deep = True, cloneTags = True):
- if self.parent is not None:
- if deep:
- parent = self.parent.clone(cloneTags = False)
- else:
- parent = self.parent
- else:
- parent = None
- if cloneTags:
- tag = self.tag.clone(deep = deep)
- else:
- tag = self.tag
- if self._remembrances is not None:
- remembrances = self._remembrances.copy()
- else:
- remembrances = None
- return type(self)(parent = parent, tag = tag, remembrances = remembrances)
-
-
- def __conform__(self, interface):
- '''Support IFoo(ctx) syntax.
- '''
-
- try:
- return self.locate(interface)
- except KeyError:
- return None
-
-
-
- def __repr__(self):
- rstr = ''
- if self._remembrances:
- rstr = ', remembrances=%r' % self._remembrances
-
- return '%s(tag=%r%s)' % (self.__class__.__name__, self.tag, rstr)
-
-
-
- class FactoryContext(WebContext):
- '''A context which allows adapters to be registered against it so that an object
- can be lazily created and returned at render time. When ctx.locate is called
- with an interface for which an adapter is registered, that adapter will be used
- and the result returned.
- '''
- inLocate = 0
-
- def locateHook(self, interface):
- self.inLocate += 1
- adapter = interface(self, None)
- self.inLocate -= 1
- return adapter
-
-
- def __conform__(self, interface):
- if self.inLocate:
- return None
- return WebContext.__conform__(self, interface)
-
-
-
- class SiteContext(FactoryContext):
- '''A SiteContext is created and installed on a NevowSite upon initialization.
- It will always be used as the root context, and can be used as a place to remember
- things sitewide.
- '''
- pass
-
-
- class RequestContext(FactoryContext):
- '''A RequestContext has adapters for the following interfaces:
-
- ISession
- IFormDefaults
- IFormErrors
- IHand
- IStatusMessage
- '''
- pass
-
-
- def getRequestContext(self):
- top = self.parent
- while not isinstance(top, RequestContext):
- top = top.parent
- return top
-
-
- class PageContext(FactoryContext):
- '''A PageContext has adapters for the following interfaces:
-
- IRenderer
- IRendererFactory
- IData
- '''
-
- def __init__(self, *args, **kw):
- FactoryContext.__init__(self, *args, **kw)
- if self.tag is not None and hasattr(self.tag, 'toremember'):
- for i in self.tag.toremember:
- self.remember(*i)
-
-
-
-
- NodeNotFound = stan.NodeNotFound
- TooManyNodes = stan.TooManyNodes
-
- class WovenContext(WebContext):
- key = None
- isAttrib = False
- inURL = False
- precompile = False
- inJS = False
- inJSSingleQuoteString = False
-
- def __init__(self, parent = None, tag = None, precompile = None, remembrances = None, key = None, isAttrib = None, inURL = None, inJS = None, inJSSingleQuoteString = None):
- WebContext.__init__(self, parent, tag, remembrances)
- if self.parent:
- self.precompile = parent.precompile
- self.isAttrib = parent.isAttrib
- self.inURL = parent.inURL
- self.inJS = parent.inJS
- self.inJSSingleQuoteString = parent.inJSSingleQuoteString
-
- if self.tag is not None:
- if self.tag.remember is not Unset:
- self.remember(tag.remember)
-
- if key is None:
- key = self.tag.key
-
-
- if key is not None and key is not Unset:
- if self.parent is not None and getattr(self.parent, 'key', None):
- self.key = '.'.join((self.parent.key, key))
- else:
- self.key = key
- elif self.parent is not None:
- self.key = getattr(self.parent, 'key', '')
-
- if precompile is not None:
- self.precompile = precompile
-
- if isAttrib is not None:
- self.isAttrib = isAttrib
-
- if inURL is not None:
- self.inURL = inURL
-
- if inJS is not None:
- self.inJS = inJS
-
- if inJSSingleQuoteString is not None:
- self.inJSSingleQuoteString = inJSSingleQuoteString
-
-
-
- def __repr__(self):
- rstr = ''
- if self._remembrances:
- rstr = ', remembrances=%r' % self._remembrances
-
- attribstr = ''
- if self.isAttrib:
- attribstr = ', isAttrib=True'
-
- urlStr = ''
- if self.inURL:
- urlStr = ', inURL=True'
-
- return '%s(tag=%r%s%s%s)' % (self.__class__.__name__, self.tag, rstr, attribstr, urlStr)
-
-
- def patternGenerator(self, pattern, default = None):
- warnings.warn('use Tag.patternGenerator instead', DeprecationWarning, stacklevel = 2)
- return self.tag.patternGenerator(pattern, default)
-
-
- def allPatterns(self, pattern):
- warnings.warn('use Tag.allPatterns instead', DeprecationWarning, stacklevel = 2)
- return self.tag.allPatterns(pattern)
-
-
- def onePattern(self, pattern):
- warnings.warn('use Tag.onePattern instead', DeprecationWarning, stacklevel = 2)
- return self.tag.onePattern(pattern)
-
-
- def clone(self, deep = True, cloneTags = True):
- cloned = WebContext.clone(self, deep, cloneTags)
- cloned.isAttrib = self.isAttrib
- cloned.inURL = self.inURL
- return cloned
-
-
-